import request from '@/utils/request'

// ==================== 智能匹配推荐相关API ====================

// 获取学生的匹配记录 (学生专用接口)
export function getStudentRecommendations(studentId) {
  // 添加fallback机制
  if (!studentId || studentId === 'undefined' || studentId === 'null' || studentId === '') {
    studentId = localStorage.getItem('userId') || '1'
    console.log('Fallback to localStorage userId:', studentId)
  }
  return request({
    url: '/campus/student/' + studentId + '/matches',
    method: 'get'
  })
}

// 查询匹配记录列表 (管理员接口，学生不应直接调用)
export function listMatchingRecord(query) {
  return request({
    url: '/campus/matchingRecord/list',
    method: 'get',
    params: query
  })
}

// 生成智能推荐
export function generateRecommendation(data) {
  return request({
    url: '/campus/matchingRecord/generateRecommendation',
    method: 'post',
    data: data
  })
}

// 获取学生推荐列表
export function getStudentMatches(studentId) {
  // 添加fallback机制
  if (!studentId || studentId === 'undefined' || studentId === 'null' || studentId === '') {
    studentId = localStorage.getItem('userId') || '1'
    console.log('Fallback to localStorage userId:', studentId)
  }
  return request({
    url: '/campus/matchingRecord/student/' + studentId,
    method: 'get'
  })
}

// 从推荐中申请
export function applyFromRecommendation(data) {
  console.log('Calling applyFromRecommendation with data:', data)
  return request({
    url: '/campus/application/applyFromRecommendation',
    method: 'post',
    data: data
  })
}

// 添加默认导出以确保模块正确导入
export default {
  getStudentRecommendations,
  listMatchingRecord,
  generateRecommendation,
  getStudentMatches,
  applyFromRecommendation
}